import 'package:backend.core/core/domain/entities/google_play/google_play_one_time_purchased_item_info.dart';
import 'package:backend.core/core/domain/entities/google_play/google_play_purchased_item_acknowledgement_status.dart';
import 'package:backend.purchases/domain/entities/google_play_api/google_play_api_purchased_item.dart';

abstract class UpdateGooglePlayOneTimePurchasedItemInfoFromApiOne {
  GooglePlayOneTimePurchasedItemInfo call({
    required GooglePlayOneTimePurchasedItemInfo oneTimePurchasedItemInfo,
    required GooglePlayApiOneTimePurchasedItem updatedApiOneTimePurchasedItem,
  });
}

class UpdateGooglePlayOneTimePurchasedItemInfoFromApiOneImpl
    implements UpdateGooglePlayOneTimePurchasedItemInfoFromApiOne {
  const UpdateGooglePlayOneTimePurchasedItemInfoFromApiOneImpl();

  @override
  GooglePlayOneTimePurchasedItemInfo call({
    required GooglePlayOneTimePurchasedItemInfo oneTimePurchasedItemInfo,
    required GooglePlayApiOneTimePurchasedItem updatedApiOneTimePurchasedItem,
  }) {
    if (updatedApiOneTimePurchasedItem.acknowledged) {
      return oneTimePurchasedItemInfo.copyWith(
        acknowledgementStatus: () => GooglePlayPurchasedItemAcknowledgementStatus.acknowledged,
      );
    } else {
      return oneTimePurchasedItemInfo;
    }
  }
}
